package net.maku.custom.biza.controller.reveiveable;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.validation.Valid;
import lombok.AllArgsConstructor;
import net.maku.custom.biza.controller.reveiveable.query.ReceivePayDetailQuery;
import net.maku.custom.biza.controller.reveiveable.vo.ReceivePayDetailVO;
import net.maku.custom.biza.mapper.reveiveable.ReceivePayDetailConvert;
import net.maku.custom.biza.pojo.reveiveable.ReceivePayDetailEntity;
import net.maku.custom.biza.service.reveiveable.ReceivePayDetailService;
import net.maku.framework.common.page.PageResult;
import net.maku.framework.common.utils.Result;
import org.springframework.web.bind.annotation.*;

/**
* 收款明细
*
* @author NULL
* @since 1.0.0 2022-07-13
*/
@RestController
@RequestMapping("/receivePayDetail")
@Tag(name="收款明细")
@AllArgsConstructor
public class ReceivePayDetailController {
    private final ReceivePayDetailService receivePayDetailService;

    @GetMapping("/page")
    @Operation(summary = "分页")
    public Result<PageResult<ReceivePayDetailVO>> page(@Valid ReceivePayDetailQuery query){
        PageResult<ReceivePayDetailVO> page = receivePayDetailService.page(query);

        return Result.ok(page);
    }

    @GetMapping("/{id}")
    @Operation(summary = "信息")
    public Result<ReceivePayDetailVO> get(@PathVariable("id") Long id){
        ReceivePayDetailEntity entity = receivePayDetailService.getById(id);

        return Result.ok(ReceivePayDetailConvert.INSTANCE.convert(entity));
    }

    @PostMapping("/save")
    @Operation(summary = "保存")
    public Result<String> save(@RequestBody ReceivePayDetailVO vo){
        receivePayDetailService.save(vo);

        return Result.ok();
    }

    @PostMapping("/update")
    @Operation(summary = "修改")
    public Result<String> update(@RequestBody @Valid ReceivePayDetailVO vo){
        receivePayDetailService.update(vo);

        return Result.ok();
    }

    @PostMapping("/delete")
    @Operation(summary = "删除")
    public Result<String> delete(@RequestBody List<Long> idList){
        receivePayDetailService.delete(idList);

        return Result.ok();
    }
}